#include "InputWIN.h"
#include "ComponentManager.h"

//temp
#include <iostream>

CInputWIN::CInputWIN(void)
{
	m_keyboardState = SDL_GetKeyState(NULL);
}

CInputWIN::~CInputWIN(void){}

bool CInputWIN::initialiseActionMapping(void)
{
	actionMap.insert(pair<int, int>(eMoveLeft, SDLK_LEFT));
	actionMap.insert(pair<int, int>(eMoveRight, SDLK_RIGHT));
	actionMap.insert(pair<int, int>(eAttack, SDLK_a));
	actionMap.insert(pair<int, int>(eJump, SDLK_s));
	actionMap.insert(pair<int, int>(eVolumeUp, SDLK_EQUALS));
	actionMap.insert(pair<int, int>(eVolumeDown, SDLK_MINUS));
	actionMap.insert(pair<int, int>(eQuit, SDLK_ESCAPE));
	actionMap.insert(pair<int, int>(ePause, SDLK_RETURN));

	return true;
}

void CInputWIN::doUpdate(void)
{
	//put the vents in the queue of SDL
	SDL_PumpEvents();

	if(m_keyboardState[(int)(*actionMap.find(eMoveLeft)).second])
	{
		CM.WORLD().addAction(eMoveLeft);
		CM.LOGCONSOLE().Log()<<"Input : Left key \n";
	}

	if(m_keyboardState[(int)(*actionMap.find(eMoveRight)).second])
	{
		CM.WORLD().addAction(eMoveRight);
		CM.LOGCONSOLE().Log()<<"Input : Right key \n";
	}

	if(m_keyboardState[(int)(*actionMap.find(eAttack)).second])
	{
		CM.WORLD().addAction(eAttack);
		CM.LOGCONSOLE().Log()<<"Input : A key \n";
	}
		

	if(m_keyboardState[(int)(*actionMap.find(eJump)).second])
	{
		CM.WORLD().addAction(eJump);
		CM.LOGCONSOLE().Log()<<"Input : S key \n";
	}
		

	if(m_keyboardState[(int)(*actionMap.find(eVolumeUp)).second])
	{
		CM.AUDIO().setVolume(CM.AUDIO().getVolume()+5);
		CM.LOGCONSOLE().Log()<<"Input : + key \n";
	}
		

	if(m_keyboardState[(int)(*actionMap.find(eVolumeDown)).second])
	{
		CM.AUDIO().setVolume(CM.AUDIO().getVolume()-5);
		CM.LOGCONSOLE().Log()<<"Input : - key \n";
	}
		
	if(m_keyboardState[(int)(*actionMap.find(eQuit)).second])
	{
		CM.LOGCONSOLE().Log()<<"Input : Quit\n";
		CM.WORLD().addAction(eQuit);
	}

	if(m_keyboardState[(int)(*actionMap.find(ePause)).second])
	{
		CM.LOGCONSOLE().Log()<<"Input : Pause\n";
		CM.WORLD().addAction(ePause);
	}
			
} 

